// eslint-disable-next-line import/named
import { MutationTree } from 'vuex'
import { StateInterface } from './state'

const mutation: MutationTree<StateInterface> = {
  setUserInfo (state, payload) {
    state.userInfo = payload
  },
  setPanels (state, workbenches) {
    state.workbenches = workbenches
  },
  createPanel (state, workbench) {
    state.workbenches.push(workbench)
  },
  deletePanel (state, id) {
    state.workbenches = state.workbenches.filter(e => e.id !== id)
  },
  setCurrentPanel (state, {
    id,
    shareId
  }) {
    if (id) {
      state.currentWorkbenchId = id
      state.shareId = null
    } else if (shareId) {
      state.currentWorkbenchId = shareId
      state.shareId = shareId
    }
  },
  setSharePanelInfo (state, payload) {
    state.sharePanelInfo = payload
  }
}

export default mutation
